extends KinematicBody2D
export(Vector2) var direct
export(int) var move_speed
export(int) var attack_damage
export(PackedScene) var boom_scene

# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass

func _physics_process(delta):
# warning-ignore:return_value_discarded
	var move = Vector2(delta * direct.x * move_speed,delta * direct.y * move_speed)
	move_and_collide(move)
	pass

func _on_VisibilityNotifier2D_screen_exited():
	queue_free()


func _on_AttackArea_area_entered(area):
	print("bullet get hero")
	
	if area.is_in_group("Hero"):
#		var hitbox = area.get_node("HitBox") as CollisionShape2D
		var boom = boom_scene.instance()
		
		boom.position.x = position.x
		boom.position.y = position.y
		boom.rotation_degrees = randi() % 360
		
		area.get_parent().get_parent().add_child(boom)
		
		area.get_parent().take_damage(attack_damage)
		queue_free()

